package com.tcm.doctor.web.controller;

import com.base.core.pager.PageBean;
import com.base.core.utils.R;
import com.tcm.doctor.domain.dto.DoctorFlowDto;
import com.tcm.doctor.domain.dto.DoctorFlowPageDto;
import com.tcm.doctor.service.DoctorFlowService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/doctor")
@RestController
public class DoctorFlowController {

    @DubboReference(version = "0.0.1-alpha", timeout = 6000, check = false, retries = 3)
    private DoctorFlowService doctorFlowService;

    @GetMapping("/flow/view")
    public R view(@RequestParam("userId") Long id) {
        return R.success(doctorFlowService.findById(id));
    }

    @PostMapping("/flow/save")
    public R create(@RequestBody DoctorFlowDto doctorFlowDto) {
        try{
            doctorFlowService.save(doctorFlowDto);
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success();
    }

    /**
     * 按时间分页
     * @param doctorFlowPageDto
     * @return
     */
    @GetMapping("/flow/listpage")
    public R listpage(@ModelAttribute DoctorFlowPageDto doctorFlowPageDto){
        PageBean listBean = doctorFlowService.listPage(doctorFlowPageDto);
        return R.success(listBean);
    }

}

